<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="店铺">
              <j-dict-select-tag v-model="queryParam.storeId" placeholder="请选择门店"
                                 dictCode="stm_store_info,name,store_id,status!=0"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="收支类型">
              <j-dict-select-tag v-model="queryParam.categoryType" placeholder="请选择收支类型" dictCode="fms_category_type"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="科目大类">
                <j-dict-select-tag v-model="queryParam.categoryId" placeholder="请选择科目大类"
                                   @change="handleCategoryChange" :triggerChange="true" dictCode="fms_category,name,id,cancel_flag=0"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="科目小类">
                <a-select placeholder="请选择科目小类" v-model="categorySubId" @change="handleCategorySubChange"  :options="categorySubOptions"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="发生日期">
                <a-range-picker
                                style="width:325px;"
                                :placeholder="['开始时间', '结束时间']"
                                @change="onOccurTimeChange"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('费用录入')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <fmsFeeInput-modal ref="modalForm" @ok="modalFormOk"></fmsFeeInput-modal>
    <fms-fee-input-add-modal ref="addModalForm" @ok="modalFormOk"></fms-fee-input-add-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import FmsFeeInputModal from './modules/FmsFeeInputModal'
import FmsFeeInputAddModal from './modules/FmsFeeInputAddModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import {httpAction, getAction} from '@/api/manage'

export default {
  name: 'FmsFeeInputList',
  mixins: [JeecgListMixin],
  components: {
    FmsFeeInputModal,
    FmsFeeInputAddModal
  },
  data() {
    return {
      description: '费用录入管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '店铺',
          align: 'center',
          dataIndex: 'storeId_dictText'
        },
        {
          title: '收支类型',
          align: 'center',
          dataIndex: 'categoryType_dictText'
        },
        {
          title: '科目大类',
          align: 'center',
          dataIndex: 'categoryId_dictText'
        },
        {
          title: '科目小类',
          align: 'center',
          dataIndex: 'categorySubId_dictText'
        },
        {
          title: '费用金额',
          align: 'center',
          dataIndex: 'amount'
        },
        {
          title: '发生日期',
          align: 'center',
          dataIndex: 'occurTime'
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'note'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/fms/fmsFeeInput/list',
        delete: '/fms/fmsFeeInput/delete',
        deleteBatch: '/fms/fmsFeeInput/deleteBatch',
        exportXlsUrl: 'fms/fmsFeeInput/exportXls',
        importExcelUrl: 'fms/fmsFeeInput/importExcel',
        queryFmsCategorySubByMainId: '/fms/fmsCategory/queryFmsCategorySubByMainId',
      },
      categorySubOptions: [],
      categorySubId: undefined,
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    handleAdd: function () {
      this.$refs.addModalForm.add();
      this.$refs.addModalForm.title = "新增";
      this.$refs.addModalForm.disableSubmit = false;
    },
    onOccurTimeChange: function(value, dateString) {
      console.log(dateString[0], dateString[1])
      this.queryParam.occurTime_begin = dateString[0]
      this.queryParam.occurTime_end = dateString[1]
    },
    handleCategoryChange (e) {
      this.queryParam.categoryId = e;
      this.queryParam.categorySubId = undefined;
      this.categorySubId = undefined;
      console.log(this.queryParam.categorySubId)
      this.categorySubOptions = [];
      if(e !== null && e !== undefined && e !== '')
        this.getCategorySubByMainId(e.toString());
    },
    handleCategorySubChange (e) {
      this.categorySubId = e;
      this.queryParam.categorySubId = e;
      console.log(this.queryParam.categorySubId)
    },
    getCategorySubByMainId(mainId){
      getAction(this.url.queryFmsCategorySubByMainId,{mainId:mainId}).then(res=>{
        if(res.success){
          this.categorySubOptions = res.result.map(data => ({ label: data['name'], value: data['id'] }));
        }else{
          console.log(res.message);
        }
      });
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>